package entity;


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;


@Entity
@Table(name="Users")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
//1: Teacher
//2: Student
@NamedQueries({
    @NamedQuery(name = "Users.findByUserPassword", query = "SELECT u FROM Users u WHERE u.userName =:username "
            + "AND u.userPassword =:userpassword AND u.active =:active"),
    @NamedQuery(name = "Users.UpdateActivation", query = "UPDATE Users u SET u.active =:active WHERE u.id =:id "),
    @NamedQuery(name = "Users.bFindByTypeNumberID", query = "SELECT u FROM Users u WHERE u.identificationType = :iDtype AND u.identificationNumber =:number"),
    @NamedQuery(name = "Users.bFindByTypeNumberIDEdit", query = "SELECT u FROM Users u WHERE u.identificationType = :iDtype AND u.identificationNumber =:number AND u.id <>:id"),
    @NamedQuery(name = "Users.bFindUserName", query = "SELECT u FROM Users u WHERE u.userName = :username"),
    @NamedQuery(name = "Users.bFindUserNameEdit", query = "SELECT u FROM Users u WHERE u.userName = :username AND u.id <>:id")
})

public class Users implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "name", length = 100, nullable = true)
    private String name;

    @Column(name = "surname", length = 100, nullable = true)
    private String surname;

    @Column(name = "IdentificationNumber")
    private Long identificationNumber;

    @Enumerated(EnumType.STRING)
    //@Column(nullable = false)
    private IdentificationType identificationType;

    @Enumerated(EnumType.STRING)
    //@Column(nullable = false)
    private UserType userType;

    @Column(name = "username", length = 100, nullable = false)
    private String userName;

    @Column(name = "userpassword", length = 100, nullable = false)
    private String userPassword;

    @Column(name = "active", length = 100, nullable = false)
    private Boolean active;
    
    @Column(name = "urlImage")
    private String urlImage;
    
    @Lob
    @Column(name = "photo_data", nullable = true)
    private byte[] photoData;

    @ManyToOne
    @JoinColumn(name = "university_id", referencedColumnName = "id")
    private University university;

//    @OneToMany(mappedBy = "user")
//    private List<ProjectUser> projectUserLst;
//    
//    @OneToMany(mappedBy = "user")
//    private List<Inventor> inventorLst;
//    
//    @OneToMany(mappedBy = "user")
//    private List<ProjectFile> projectFileLst;
//    
//    
//    
//    @OneToMany(mappedBy = "user")
//    private List<SoftwareUser> softwareUserLst;

    //COMMENT: 
    //Se deberia eliminar la cascasda. Se considera que una usersa
    //es creada por el usuario administrador, el cual no setea la work experience.
//    @OneToMany(mappedBy = "users", cascade = CascadeType.ALL)
//    private List<WorkExperience> workExperienceLst;

//    @OneToMany(mappedBy = "users", cascade = CascadeType.ALL)
//    private List<ResearchExperience> researchExperienceLst;
//
//    @OneToMany(mappedBy = "users", cascade = CascadeType.ALL)
//    private List<GraduateStudies> graduateStudiesLst;

//    @OneToMany(mappedBy = "users", cascade = CascadeType.ALL)
//    private List<UserSkill> LstUserSkill;
//    
//    @OneToMany(mappedBy = "users", cascade = CascadeType.ALL)
//    private List<UserInvestigationLine> userInvestigationLinesLst;    

//    @OneToMany
//    @JoinTable(name = "User_OutputMessage")
//    private List<Message> outputMessagesLst;
//
//    @OneToMany
//    @JoinTable(name = "User_InputMessage")
//    private List<Message> inputMessagesLst;
    
    //    
//    @OneToMany (mappedBy="users", cascade= CascadeType.PERSIST)
//    private List <GraduateStudies> graduateStudiesLst;

//    public List<Message> getOutputMessagesLst() {
//        return outputMessagesLst;
//    }
//
//    public void setOutputMessagesLst(List<Message> outputMessagesLst) {
//        this.outputMessagesLst = outputMessagesLst;
//    }
//
//    public List<Message> getInputMessagesLst() {
//        return inputMessagesLst;
//    }
//
//    public void setInputMessagesLst(List<Message> inputMessagesLst) {
//        this.inputMessagesLst = inputMessagesLst;
//    }
//
//    public List<Inventor> getInventorLst() {
//        return inventorLst;
//    }
//
//    public void setInventorLst(List<Inventor> inventorLst) {
//        this.inventorLst = inventorLst;
//    }
//    
//    
//    public List<SoftwareUser> getSoftwareUserLst() {
//        return softwareUserLst;
//    }
//
//    public void setSoftwareUserLst(List<SoftwareUser> softwareUserLst) {
//        this.softwareUserLst = softwareUserLst;
//    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUrlImage() {
        return urlImage;
    }

    public void setUrlImage(String urlImage) {
        this.urlImage = urlImage;
    }

//    public List<ProjectUser> getProjectUserLst() {
//        return projectUserLst;
//    }
//
//    public void setProjectUserLst(List<ProjectUser> projectUserLst) {
//        this.projectUserLst = projectUserLst;
//    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public Long getIdentificationNumber() {
        return identificationNumber;
    }

    public void setIdentificationNumber(Long identificationNumber) {
        this.identificationNumber = identificationNumber;
    }

    public IdentificationType getIdentificationType() {
        return identificationType;
    }

    public void setIdentificationType(IdentificationType identificationType) {
        this.identificationType = identificationType;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

//    public List<WorkExperience> getLstWorkExperience() {
//        return workExperienceLst;
//    }
//
//    public void setLstWorkExperiences(List<WorkExperience> workExperienceLst) {
//        this.workExperienceLst = workExperienceLst;
//    }

//    public List<GraduateStudies> getGraduateStudiesLst() {
//        return graduateStudiesLst;
//    }
//
//    public void setLstGraduateStudies(List<GraduateStudies> graduateStudiesLst) {
//        this.graduateStudiesLst = graduateStudiesLst;
//    }

    public University getUniversity() {
        return university;
    }

    public void setUniversity(University university) {
        this.university = university;
    }

    public UserType getUserType() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType = userType;
    }

//    public List<WorkExperience> getWorkExperienceLst() {
//        return workExperienceLst;
//    }
//
//    public void setWorkExperienceLst(List<WorkExperience> workExperienceLst) {
//        this.workExperienceLst = workExperienceLst;
//    }

//    public List<ResearchExperience> getResearchExperienceLst() {
//        return researchExperienceLst;
//    }
//
//    public void setLstResearchExperiences(List<ResearchExperience> researchExperienceLst) {
//        this.researchExperienceLst = researchExperienceLst;
//    }

//    public List<UserSkill> getLstUserSkill() {
//        return LstUserSkill;
//    }
//
//    public void setLstUserSkill(List<UserSkill> LstUserSkill) {
//        this.LstUserSkill = LstUserSkill;
//    }
//
//    public List<UserInvestigationLine> getUserInvestigationLinesLst() {
//        return userInvestigationLinesLst;
//    }
//
//    public void setUserInvestigationLinesLst(List<UserInvestigationLine> userInvestigationLinesLst) {
//        this.userInvestigationLinesLst = userInvestigationLinesLst;
//    }
    

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }

//    public List<ProjectFile> getProjectFileLst() {
//        return projectFileLst;
//    }
//
//    public void setProjectFileLst(List<ProjectFile> projectFileLst) {
//        this.projectFileLst = projectFileLst;
//    }

    public byte[] getPhotoData() {
        return photoData;
    }

    public void setPhotoData(byte[] photoData) {
        this.photoData = photoData;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entidad.Users[ id=" + id + " ]";
    }

}

